package com.ctesi.utils;

import com.alibaba.fastjson.JSONObject;
import us.codecraft.webmagic.Page;


public class JsonUtil {

    //浙江裂变url
    public static void ZheJiangPostUrlParse(String context, Page page) {
        JSONObject jsonObject = JSONObject.parseObject(context);

        for (int i = 0; i < 12; i++) {
            JSONObject response = jsonObject.getJSONObject("result").getJSONArray("records").getJSONObject(i);
            String url = "http://zjpubservice.zjzwfw.gov.cn" + response.getString("linkurl");
            if (url.contains("2023")) {
                page.addTargetRequest(url);
            } else {
                System.out.println(url + "不是2023年的，舍去。");
            }
        }
        System.out.println("---------------------------添加裂变url成功--------------------------");

    }

    //江苏省裂变url
    public static void JiangSuPostUrlParse(String context, Page page) {
        JSONObject jsonObject = JSONObject.parseObject(context);

        for (int i = 0; i < 12; i++) {
            JSONObject response = jsonObject.getJSONObject("result").getJSONArray("records").getJSONObject(i);
            String url = "http://jsggzy.jszwfw.gov.cn" + response.getString("linkurl");
            if (url.contains("2023")) {
                page.addTargetRequest(url);
            } else {
                System.out.println(url + "不是2023年的，舍去。");
            }
        }
        System.out.println("---------------------------添加裂变url成功--------------------------");

    }

    //江西裂变url
    public static void GuangXiPostUrlParse(String context, Page page) {
        JSONObject jsonObject = JSONObject.parseObject(context);
        for (int i = 0; i < 10; i++) {
            JSONObject response = jsonObject.getJSONObject("page").getJSONArray("content").getJSONObject(i);
            String url = response.getString("DOCPUBURL");
            page.addTargetRequest(url);
            System.out.println(url + "添加成功");
        }
        System.out.println("---------------------------添加裂变url成功--------------------------");

    }


}
